package xfsale.service.impl.j2ee;

import java.sql.Connection;
import java.sql.PreparedStatement;

import org.apache.log4j.Logger;

@SuppressWarnings("unused")
public final class PubLog {

    private String logSerialNo;         //操作日志流水
    private String orderSerialNo;		//委托流水
    private String serviceCode;			//功能码
    private String businessCode;        //业务码
    private String acceptMethod;		//受理方式
    private String regionCode;			//地区代码
    private String branchCode;			//网点代码
    private String netCode;             //销售网点代码
    private String opCode;				//操作员代码
    private String opDate;				//操作日期
    private String opTime;				//操作时间
    private String ipAddr;				//IP地址
    private String macAddr;				//MAC地址
    private String returnCode;			//返回代码
    private String returnMsg;			//返回信息
    private Connection conn;			//数据库连接
    private Logger logger = Logger.getLogger(PubAcct.class);	//日志

    public PubLog(Connection conn) {
        this.conn = conn;
    }

    public void setLogSerialNo(String opLogSerialNo) {
        this.logSerialNo = opLogSerialNo;
    }

    public void setOrderSerialNo(String orderSerialNo) {
        this.orderSerialNo = orderSerialNo;
    }

    public void setServiceCode(String serviceCode) {
        this.serviceCode = serviceCode;
    }

    public void setBusinessCode(String businessCode) {
        this.businessCode = businessCode;
    }

    public void setAcceptMethod(String acceptMethod) {
        this.acceptMethod = acceptMethod;
    }

    public void setRegionCode(String regionCode) {
        this.regionCode = regionCode;
    }

    public void setBranchCode(String branchCode) {
        this.branchCode = branchCode;
    }

    public void setNetCode(String netCode) {
        this.netCode = netCode;
    }

    public void setOpCode(String opCode) {
        this.opCode = opCode;
    }

    public void setOpDate(String opDate) {
        this.opDate = opDate;
    }

    public void setOpTime(String opTime) {
        this.opTime = opTime;
    }

    public void setIpAddr(String ipAddr) {
        this.ipAddr = ipAddr;
    }

    public void setMacAddr(String macAddr) {
        this.macAddr = macAddr;
    }

    public void setReturnCode(String returnCode) {
        this.returnCode = returnCode;
    }

    public void setReturnMsg(String returnMsg) {
        this.returnMsg = returnMsg;
    }

    public void writeLog() throws Exception {
        PubSerial serial = new PubSerial(conn);
        serial.setTradeDate(opDate);
        serial.genLogSerial();
        logSerialNo = serial.getLogSerialNo();

        PreparedStatement stmt = null;
        try {
            logger.info("写入操作日志...");
            stmt = conn.prepareStatement(""
                    + "insert into OpLog"
                    + "("
                    + "	logSerialNo, "
                    + "	serviceCode, "
                    + "	businessCode, "
                    + "	orderSerialNo, "
                    + "	acceptMethod, "
                    + "	regionCode, "
                    + "	branchCode, "
                    + "	netCode, "
                    + "	opCode, "
                    + "	opDate, "
                    + "	opTime, "
                    + "	returnCode, "
                    + "	returnMsg, "
                    + "	ipAddr, "
                    + "	macAddr, "
                    + "	summary "
                    + ")"
                    + "values "
                    + "( "
                    + "	?, "
                    + "	?, "
                    + "	?, "
                    + "	?, "
                    + "	?, "
                    + "	?, "
                    + "	?, "
                    + "	?, "
                    + "	?, "
                    + "	?, "
                    + "	?, "
                    + "	?, "
                    + "	?, "
                    + "	?, "
                    + "	?, "
                    + "	? "
                    + ")");
            stmt.setString(1, logSerialNo);
            stmt.setString(2, serviceCode);
            stmt.setString(3, businessCode);
            stmt.setString(4, orderSerialNo);
            stmt.setString(5, acceptMethod);
            stmt.setString(6, regionCode);
            stmt.setString(7, branchCode);
            stmt.setString(8, netCode);
            stmt.setString(9, opCode);
            stmt.setString(10, opDate);
            stmt.setString(11, opTime);
            stmt.setString(12, returnCode);
            stmt.setString(13, returnMsg);
            stmt.setString(14, ipAddr);
            stmt.setString(15, macAddr);
            stmt.setString(16, "");
            stmt.executeUpdate();
            conn.commit();
            logger.debug("写入操作日志成功.");
        } catch (Exception e) {
            logger.error("写入操作日志出错. " + e);
            throw e;
        } finally {
            stmt.close();
        }
    }
}
